package Demo24;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
class JavaCalum extends JFrame implements ActionListener{
    private JButton jb1 = new JButton("=");
    private JTextField jt1 = new JTextField(10);
    private JTextField jt2 = new JTextField(10);
    private JTextField jt3 = new JTextField(10);
    private JLabel jl = new JLabel("+");
    public JavaCalum() {
        super("简单计算器");
        super.setBounds(200,200,500,500);
        super.getContentPane().setLayout(new FlowLayout());
        super.getContentPane().add(jt1);
        super.getContentPane().add(jl);
        super.getContentPane().add(jt2);
        super.getContentPane().add(jb1);
        super.getContentPane().add(jt3);
        jb1.addActionListener(this);
        super.setVisible(true);
    }
    public static void main(String args[]){
        new JavaCalum();
    }
    public void actionPerformed(ActionEvent e){
        if(e.getSource()==jb1){
            double a = Double.parseDouble(jt1.getText());
            double b = Double.parseDouble(jt2.getText());
            double c = a+b;
            String string= Double.toString(c);
            jt3.setText(string);
        }
    }
}
